package convertor

import (
	commonTools "algo-sdk-go/common/tools"
	"algo-sdk-go/project/matchmaking/adapter/po"
	"algo-sdk-go/project/matchmaking/domain/models/entity"
	"algo-sdk-go/project/matchmaking/domain/models/valueobject"
	"algo-sdk-go/project/matchmaking/domain/port/repo/ops"

	"go.mongodb.org/mongo-driver/bson/primitive"
)

func ConvertMatePreferenceToPo(matePreference *entity.MatePreference) *po.MatePreference {
	return &po.MatePreference{
		Id:        primitive.NewObjectID().Hex(),
		UserNum:   matePreference.UserNum,
		Standards: matePreference.Standards,

		MinHeight:    matePreference.HeightRange.MinHeight,
		MaxHeight:    matePreference.HeightRange.MaxHeight,
		MinWeight:    matePreference.WeightRange.MinWeight,
		MaxWeight:    matePreference.WeightRange.MaxWeight,
		MinAge:       matePreference.AgeRange.MinAge,
		MaxAge:       matePreference.AgeRange.MaxAge,
		MinIncome:    matePreference.IncomeRange.MinIncome,
		MaxIncome:    matePreference.IncomeRange.MaxIncome,
		MinEducation: matePreference.EducationRange.MinEducation,
		MaxEducation: matePreference.EducationRange.MaxEducation,

		OccupationPreference:       matePreference.OccupationPreference,
		HometownPreference:         commonTools.Cast(matePreference.HometownPreference, valueobject.CodeAddress),
		CurrentResidencePreference: commonTools.Cast(matePreference.CurrentResidencePreference, valueobject.CodeAddress),
		PersonalityTraits:          matePreference.PersonalityTraits,
		OtherRequired:              matePreference.OtherRequired,
		Status:                     "",
		IsDeleted:                  false,
		CreateUser:                 matePreference.CreateUser,
		CreateTime:                 commonTools.TimeNowStr(),
		ModifyUser:                 matePreference.ModifyUser,
		UpdateTime:                 commonTools.TimeNowStr(),
	}
}

func ConvertMatePreferenceToEntity(matePreference *po.MatePreference) entity.MatePreference {
	return entity.MatePreference{
		UserNum:   matePreference.UserNum,
		Standards: matePreference.Standards,
		Gender:    "",

		WeightRange: ops.WeightRange{
			MinWeight: matePreference.MinWeight,
			MaxWeight: matePreference.MaxWeight,
		},
		HeightRange: ops.HeightRange{
			MinHeight: matePreference.MinHeight,
			MaxHeight: matePreference.MaxHeight,
		},
		AgeRange: ops.AgeRange{
			MinAge: matePreference.MinAge,
			MaxAge: matePreference.MaxAge,
		},
		IncomeRange: ops.IncomeRange{
			MinIncome: matePreference.MinIncome,
			MaxIncome: matePreference.MaxIncome,
		},
		EducationRange: ops.EducationRange{
			MinEducation: matePreference.MinEducation,
			MaxEducation: matePreference.MaxEducation,
		},

		OccupationPreference:       matePreference.OccupationPreference,
		HometownPreference:         commonTools.Cast(matePreference.HometownPreference, valueobject.DecodeAddress),
		CurrentResidencePreference: commonTools.Cast(matePreference.CurrentResidencePreference, valueobject.DecodeAddress),
		PersonalityTraits:          matePreference.PersonalityTraits,
		OtherRequired:              matePreference.OtherRequired,
		CreateUser:                 matePreference.CreateUser,
		ModifyUser:                 matePreference.ModifyUser,
	}
}
